<?php

namespace App\Http\Controllers;
Use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use GuzzleHttp\Client;
use App\Jobs\AddImageToLocalJob;

class HomeController extends Controller
{
	public function index()
	{
		return view('home.index');
	}

	public function product()
	{
		return view('home.product');
	}


	public function produce()
	{
		return view('home.produce');
	}


	public function aboutus()
	{
		return view('home.aboutus');
	}


	public function alioss()
	{
		$url = request('url');
		$path = base64_decode($url);

		$hz = explode('.',$path);
		$endHz = end($hz);
		
		if($endHz != 'jpg' &&  $endHz != 'png' && $endHz !='jpeg'){

			return false;
		}
		$client = new Client();

		$fileNameArr = explode('/',$path);

		$fileName = end($fileNameArr);

		
		if(file_exists(public_path('app')."/".$fileName)){
			return file_get_contents(Storage::disk('public')->url($fileName));
		}else{

			$response = $client->request('GET', Storage::url($path), [

			]);
			//dd(123);
			

			dispatch(new AddImageToLocalJob($path))->onQueue('plusImage');
			
			return $response->getBody();
		}
		

	}
}
